package com.tools.middle.elasticsearch;

import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
import co.elastic.clients.elasticsearch.core.search.HighlightField;
import com.tools.common.container.OwnPairs;
import com.tools.common.object.Note;
import com.tools.common.thread.Timeunit;

import java.util.Map;

/**
 * 单字段的 prefix 前缀匹配包装类。
 * 继承父类的方法在多条件查询时不起作用（除了分词器）
 * */
@Note("单字段的 prefix 前缀匹配包装类。" +
        "继承父类的方法在多条件查询时不起作用（除了分词器）")
public final class PrefixSearch extends Search {

    @Note("字段名称")
    private String field;

    @Note("要前缀匹配查询的内容")
    private String query;

    /* **********************************************************************************
     *
     *          构造器
     *
     * *********************************************************************************
     * */

    public PrefixSearch(String field, String query) {
        this.setField(field);
        this.setQuery(query);
    }

    public static PrefixSearch of(String field, String query) {
        return new PrefixSearch(field, query);
    }

    /* **********************************************************************************
     *
     *          Getter / Setter
     *
     * *********************************************************************************
     * */

    public String getField() {
        return field;
    }

    public void setField(String field) {
        default_fieldNotEmpty(field);
        this.field = field;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        if(query == null || query.isEmpty()) throw new IllegalArgumentException("要查询的内容为空");
        this.query = query;
    }

    /* **********************************************************************************
     *
     *          链式调用
     *
     * *********************************************************************************
     * */

    public PrefixSearch field(String field) {
        this.setField(field);
        return this;
    }

    public PrefixSearch query(String query) {
        this.setQuery(query);
        return this;
    }

    @Override
    public PrefixSearch indicesNames(String indicesName) {
        super.indicesNames(indicesName);
        return this;
    }

    @Override
    public PrefixSearch indicesNames(String... indicesNames) {
        super.indicesNames(indicesNames);
        return this;
    }

    @Override
    public PrefixSearch indicesNames(Iterable<String> indicesNames) {
        super.indicesNames(indicesNames);
        return this;
    }

    @Override
    public PrefixSearch timeout(String timeout) {
        super.timeout(timeout);
        return this;
    }

    @Override
    public PrefixSearch timeout(int timeout, Timeunit timeunit) {
        super.timeout(timeout, timeunit);
        return this;
    }

    @Override
    public PrefixSearch from(int from) {
        super.from(from);
        return this;
    }

    @Override
    public PrefixSearch size(int size) {
        super.size(size);
        return this;
    }

    @Override
    public PrefixSearch analyzer(String analyzer) {
        super.analyzer(analyzer);
        return this;
    }

    @Override
    public PrefixSearch sorts(String field, SortOrder order) {
        super.sorts(field, order);
        return this;
    }

    @Override
    public PrefixSearch sorts(Map<String, SortOrder> fieldAndOrders) {
        super.sorts(fieldAndOrders);
        return this;
    }

    @Override
    public PrefixSearch sorts(OwnPairs<String, SortOrder> fieldAndOrders) {
        super.sorts(fieldAndOrders);
        return this;
    }

    @Override
    public PrefixSearch includes(String includeField) {
        super.includes(includeField);
        return this;
    }

    @Override
    public PrefixSearch includes(String... includeFields) {
        super.includes(includeFields);
        return this;
    }

    @Override
    public PrefixSearch includes(Iterable<String> includeFields) {
        super.includes(includeFields);
        return this;
    }

    @Override
    public PrefixSearch excludes(String excludeField) {
        super.excludes(excludeField);
        return this;
    }

    @Override
    public PrefixSearch excludes(String... excludeFields) {
        super.excludes(excludeFields);
        return this;
    }

    @Override
    public PrefixSearch excludes(Iterable<String> excludeFields) {
        super.excludes(excludeFields);
        return this;
    }

    @Override
    public PrefixSearch aggregations(String field, Aggregation agg) {
        super.aggregations(field, agg);
        return this;
    }

    @Override
    public PrefixSearch aggregations(Map<String, Aggregation> aggregations) {
        super.aggregations(aggregations);
        return this;
    }

    @Override
    public PrefixSearch aggregations(OwnPairs<String, Aggregation> aggregations) {
        super.aggregations(aggregations);
        return this;
    }

    @Override
    public PrefixSearch highlights(String field, HighlightField highlight) {
        super.highlights(field, highlight);
        return this;
    }

    @Override
    public PrefixSearch highlights(Map<String, HighlightField> highlights) {
        super.highlights(highlights);
        return this;
    }

    @Override
    public PrefixSearch highlights(OwnPairs<String, HighlightField> highlights) {
        super.highlights(highlights);
        return this;
    }

    /* **********************************************************************************
     *
     *          自定义方法
     *
     * *********************************************************************************
     * */

    @Override
    public PrefixSearch addIndicesName(String indicesName) {
        super.addIndicesName(indicesName);
        return this;
    }

    @Override
    public PrefixSearch addIndicesNames(String... indicesNames) {
        super.addIndicesNames(indicesNames);
        return this;
    }

    @Override
    public PrefixSearch addIndicesNames(Iterable<String> indicesNames) {
        super.addIndicesNames(indicesNames);
        return this;
    }

    @Override
    public PrefixSearch modifyIndicesName(int index, String indicesName) {
        super.modifyIndicesName(index, indicesName);
        return this;
    }

    @Override
    public PrefixSearch removeIndicesName(String indicesName) {
        super.removeIndicesName(indicesName);
        return this;
    }

    @Override
    public PrefixSearch removeIndicesName(int index) {
        super.removeIndicesName(index);
        return this;
    }

    @Override
    public PrefixSearch removeIndicesNames(String... indicesNames) {
        super.removeIndicesNames(indicesNames);
        return this;
    }

    @Override
    public PrefixSearch removeIndicesNames(Iterable<String> indicesNames) {
        super.removeIndicesNames(indicesNames);
        return this;
    }

    @Override
    public PrefixSearch addSort(String field, SortOrder order) {
        super.addSort(field, order);
        return this;
    }

    @Override
    public PrefixSearch addSorts(Map<String, SortOrder> fieldAndOrders) {
        super.addSorts(fieldAndOrders);
        return this;
    }

    @Override
    public PrefixSearch addSorts(OwnPairs<String, SortOrder> fieldAndOrders) {
        super.addSorts(fieldAndOrders);
        return this;
    }

    @Override
    public PrefixSearch modifySort(int index, String field, SortOrder order) {
        super.modifySort(index, field, order);
        return this;
    }

    @Override
    public PrefixSearch clearSorts() {
        super.clearSorts();
        return this;
    }

    @Override
    public PrefixSearch removeSort(String field, SortOrder order) {
        super.removeSort(field, order);
        return this;
    }

    @Override
    public PrefixSearch removeSort(int index) {
        super.removeSort(index);
        return this;
    }

    @Override
    public PrefixSearch removeSorts(Map<String, SortOrder> fieldAndOrders) {
        super.removeSorts(fieldAndOrders);
        return this;
    }

    @Override
    public PrefixSearch removeSorts(OwnPairs<String, SortOrder> fieldAndOrders) {
        super.removeSorts(fieldAndOrders);
        return this;
    }

    @Override
    public PrefixSearch addInclude(String field) {
        super.addInclude(field);
        return this;
    }

    @Override
    public PrefixSearch addIncludes(String... fields) {
        super.addIncludes(fields);
        return this;
    }

    @Override
    public PrefixSearch addIncludes(Iterable<String> fields) {
        super.addIncludes(fields);
        return this;
    }

    @Override
    public PrefixSearch modifyInclude(int index, String field) {
        super.modifyInclude(index, field);
        return this;
    }

    @Override
    public PrefixSearch clearIncludes() {
        super.clearIncludes();
        return this;
    }

    @Override
    public PrefixSearch removeInclude(String field) {
        super.removeInclude(field);
        return this;
    }

    @Override
    public PrefixSearch removeInclude(int index) {
        super.removeInclude(index);
        return this;
    }

    @Override
    public PrefixSearch removeIncludes(String... fields) {
        super.removeIncludes(fields);
        return this;
    }

    @Override
    public PrefixSearch removeIncludes(Iterable<String> fields) {
        super.removeIncludes(fields);
        return this;
    }

    @Override
    public PrefixSearch addExclude(String field) {
        super.addExclude(field);
        return this;
    }

    @Override
    public PrefixSearch addExcludes(String... fields) {
        super.addExcludes(fields);
        return this;
    }

    @Override
    public PrefixSearch addExcludes(Iterable<String> fields) {
        super.addExcludes(fields);
        return this;
    }

    @Override
    public PrefixSearch modifyExclude(int index, String field) {
        super.modifyExclude(index, field);
        return this;
    }

    @Override
    public PrefixSearch clearExcludes() {
        super.clearExcludes();
        return this;
    }

    @Override
    public PrefixSearch removeExclude(String field) {
        super.removeExclude(field);
        return this;
    }

    @Override
    public PrefixSearch removeExclude(int index) {
        super.removeExclude(index);
        return this;
    }

    @Override
    public PrefixSearch removeExcludes(String... fields) {
        super.removeExcludes(fields);
        return this;
    }

    @Override
    public PrefixSearch removeExcludes(Iterable<String> fields) {
        super.removeExcludes(fields);
        return this;
    }

    @Override
    public PrefixSearch addAgg(String field, Aggregation agg) {
        super.addAgg(field, agg);
        return this;
    }

    @Override
    public PrefixSearch addAggs(Map<String, Aggregation> aggs) {
        super.addAggs(aggs);
        return this;
    }

    @Override
    public PrefixSearch addAggs(OwnPairs<String, Aggregation> aggs) {
        super.addAggs(aggs);
        return this;
    }

    @Override
    public PrefixSearch clearAggs() {
        super.clearAggs();
        return this;
    }

    @Override
    public PrefixSearch removeAgg(String field) {
        super.removeAgg(field);
        return this;
    }

    @Override
    public PrefixSearch removeAgg(String... fields) {
        super.removeAgg(fields);
        return this;
    }

    @Override
    public PrefixSearch removeAgg(Iterable<String> fields) {
        super.removeAgg(fields);
        return this;
    }

    @Override
    public PrefixSearch addHighlight(String field, HighlightField highlight) {
        super.addHighlight(field, highlight);
        return this;
    }

    @Override
    public PrefixSearch addHighlights(Map<String, HighlightField> highlights) {
        super.addHighlights(highlights);
        return this;
    }

    @Override
    public PrefixSearch addHighlights(OwnPairs<String, HighlightField> highlights) {
        super.addHighlights(highlights);
        return this;
    }

    @Override
    public PrefixSearch clearHighlight() {
        super.clearHighlight();
        return this;
    }

    @Override
    public PrefixSearch removeHighlight(String field) {
        super.removeHighlight(field);
        return this;
    }

    @Override
    public PrefixSearch removeHighlights(String... fields) {
        super.removeHighlights(fields);
        return this;
    }

    @Override
    public PrefixSearch removeHighlights(Iterable<String> fields) {
        super.removeHighlights(fields);
        return this;
    }
}
